#!/usr/bin/perl
require "pdcusrgroup-lib.pl";

&ReadParse();

my($disfile, @userlist, $i, $trcls, @grouplist, $tablelength, $failed, %fullname, %members);
my ($display);

$display = $in{"i_display"};
unless($display)
{
	$display = "dis_user";
}


$disfile = $in{"disfile"};

if(!$disfile)
{
	$disfile = "getuser";
}

&header($text{'index_title'}, "", "index", 0, 1);

if($display eq "dis_user")
{
	@userlist = &get_pdcuser_list();
	&getent_passwd_fullname(\%fullname);
}
if($display eq "dis_group")
{
	@grouplist = &get_pdcgroup_list();
	&getent_group_members(\%members);
}
print "<form name=formpdcusergroup action=index.cgi method=post onsubmit='return onsubmit_form();'>";

print "<table class=mode1 border=0 width=100%>";

print "<tr><td valign=top width=80%>";

print "<div style='valign:top;width:100%;height:300;overflow:auto'>";

print "<table class=mode1 width=100% cellspacing=0 border=0>";

if($display eq "dis_user")
{

	print "<tr class=title1><th width=45% align=left>$text{'th_username'}</th><th width=55% align=left>$text{'th_fullname'}</th></tr>";

	
	$i = 0;
	while($i < @userlist)
	{
		if($i %2)
		{
			$trcls = "class=mode2";
		}
		else
		{
			$trcls = "class=mode1";
		}
		print "<tr $trcls><td>$userlist[$i]</td>";
		print "<td>$fullname{$userlist[$i]}</td></tr>";
	$i++;
	}
}
elsif($display eq "dis_group")
{
	print "<tr class=title1><th width=45% align=left>$text{'th_groupname'}</th><th width=55% align=left>$text{'th_groupmembers'}</th></tr>";
	

	$i = 0;
	while($i < @grouplist)
	{
		if($i %2)
		{
			$trcls = "class=mode2";
		}
		else
		{
			$trcls = "class=mode1";
		}
		print "<tr $trcls><td>$grouplist[$i]</td>";
		print "<td>$members{$grouplist[$i]}</td></tr>";
		$i++;
	}
}



print "</table>";

print "</div>";

print "</td><td valign=top align=center>";

print "<table>";

#print "<tr><td><input name=submit_getuser type=submit class=button value=\"$text{'sb_getuser'}\"></td><tr>";
#print "<tr><td><input name=submit_getgroup type=submit class=button value=\"$text{'sb_getgroup'}\"></td><tr>";
print "<tr><td><input name=submit_refeshtable type=submit class=button onclick='return on_submit_click_refeshtable();' value=\"$text{'sb_pdcrefeshtable'}\"></td></tr>";
#print "<tr><td><input name=submit_storedomainpasswd type=submit class=button onclick='return on_submit_click_dmpasswd();' value=\"$text{'sb_storedomainpasswd'}\"></td><tr>";
if($display eq "dis_user")
{
	print "<tr><td><input name=submit_display type=submit class=button onclick=\"return on_displaygroup_click();\" value=\"$text{'sb_display_group'}\"></td></tr>";
}
else
{
	print "<tr><td><input name=submit_display type=submit class=button onclick=\"return on_displayuser_click();\" value=\"$text{'sb_display_user'}\"></td></tr>";
}
print "</table>";

print "<td></tr>";

print "</table>";

#print "<input type=text name=disfile value=\"getuser\">";
print "<input type=hidden name=i_display value=\"$display\">";

print "</form>";

print <<EOF;
<script>
function onsubmit_form()
{
        document.forms[0].submit_refeshtable.disabled = true;
        document.forms[0].submit_display.disabled = true;
//        document.forms[0].submit_storedomainpasswd.disabled = true;
}

function on_submit_click_refeshtable()
{
	document.forms[0].action = "refreshtable.cgi";
}

function on_submit_click_dmpasswd()
{
	document.forms[0].action = "eddomainpassword.cgi";
}

function on_displayuser_click()
{
	document.forms[0].i_display.value = "dis_user";
	document.forms[0].action = "index.cgi";
}

function on_displaygroup_click()
{

	document.forms[0].i_display.value = "dis_group";
	document.forms[0].action = "index.cgi";
}

</script>
EOF

&footer("/", $text{'index'});
